#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
LL d[maxn],tot=0;
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m,a,b;cin>>n>>m>>a>>b;
  if(n<m){
    LL cnt=m-n;
    cout<<(cnt)*a<<endl;
  }
  else if(n>m){
    if(n%m==0){
        cout<<0<<endl;
    }
    else{
        LL cnt=n%m;
        LL down=cnt;
        LL up=m-cnt;
        cout<<min(down*b,up*a)<<endl;
    }
  }
return 0;
}
